package com.atguigu.gmall.item.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.service.BloomFilterService;
import org.redisson.api.RBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/bloom")
@RestController
public class BloomController {

    @Autowired
    RBloomFilter<Object> skuIdBloom;

    @Autowired
    BloomFilterService bloomFilterServicel;

    @GetMapping("/rebuild")
    public Result rebuildBloom(){
        //重建布隆
        bloomFilterServicel.rebuildBloom(skuIdBloom,
                1000000,
                0.00001);
        return Result.ok();
    }

    @GetMapping("/{skuId}")
    public Result testCOntaines(@PathVariable("skuId") Long skuId){
        boolean contains = skuIdBloom.contains(skuId);
        return Result.ok(contains);
    }

    @GetMapping("/str/{skuId}")
    public Result test2(@PathVariable("skuId")String skuId){
        boolean contains = skuIdBloom.contains(skuId);
        return Result.ok(contains);
    }
}
